package com.wzx.basics.exception;

import com.wzx.basics.baseVo.Result;
import com.wzx.basics.utils.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return ResultUtil.error("执行了全局异常处理");
    }
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public Result error(ArithmeticException e){
        e.printStackTrace();
        return ResultUtil.error("执行了特定异常处理");
    }
    @ExceptionHandler(WzxException.class)
    @ResponseBody
    public Result error(WzxException e){
        e.printStackTrace();
        return  ResultUtil.error(e.getMsg());
    }
}